package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.UserMapper;
import com.zld.smarket.pojo.User;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public ResponseData getUser(HttpServletRequest request, String username, String password) {
        User user = userMapper.selectByUserName(username);
        if(user==null){
            return  new ResponseData("0011","用户名错误",null);
        }else{
            if(user.getPassword().equals(password)){
                request.getSession().setAttribute("user",user);
                return  new ResponseData("200",user);
            }else {
                return  new ResponseData("0012","密码错误",null);
            }
        }
    }
}
